<template>
	<view class="tabcontrol" :class="{tabcontroltop:active}">
		<view class="tabcontrolitem" v-for="(item,index) in titles" v-bind:key="index" :class="{active:index===currentIndex}">
			<text v-on:click="tabControl(index)">{{item}}</text>
		</view>
	</view>
</template>

<script>
	export default {
		props:{
			titles:{
				type:Array,
				default:function (){
					return []
				}
			},
			active:{
				type:Boolean,
				default:false
			}
		},
		data() {
			return {
				currentIndex:0
			}
		},
		methods: {
			tabControl(index){
				this.currentIndex=index
				this.$emit('tabClick',index)
			}
		}
	}
</script>

<style scoped>
.tabcontrol{
    display: flex;
    background-color: white;
    padding: 5px 0;
	background-color: aliceblue;
}
.tabcontroltop{
	position: fixed;
	right: 0rpx;
	left: 0rpx;
	top: 170rpx;
	z-index: 3;
}
.tabcontrolitem{
    flex: 1;
    text-align: center;
}
text{
    line-height: 22px;
    display: inline-block;
}
.active text{
    color: red;
    border-bottom: 3px solid red;
}
</style>
